﻿using Client.Base;
using UnityEngine;
namespace Client.Hotfix
{
    /// <summary>
    /// 账号系统
    /// </summary>
    [SSM(SSMWeight.AccountSystem)]
    public class AccountSystem : IAwake,IDestroy
    {
        public string Token { get; private set; }
        public void Awake(params object[] args)
        {
            this.Log("[System] AccountSystem is running...");
            AddEventListener();
            AddMessageListener();
        }

        public void Destroy()
        {
            Api.Instance.Get<EventService>().RemoveListenerByClass(this);
            RemoveMessageListener();
        }

        public void SetToken(string token)
        {
            Token = token;
        }

        private void OnRespLogin(GameMessage message)
        {
            var resp = message.Parse<RespLoginMessage_10001>();
            Api.Instance.Get<EventService>().Call(EventCode.Event_LoginResult,true);
        }

        private void AddEventListener()
        {
           
        }


        private void AddMessageListener()
        {
            Api.Instance.Get<NetService>().AddMessageListener(10001, OnRespLogin);
        }
        private void RemoveMessageListener()
        {
            Api.Instance.Get<NetService>().RemoveMessageListener(10001, OnRespLogin);
        }

    }

}
